package com.lecyon.farm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lecyon.farm.base.BaseRequestPageVo;
import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.BaseResponse;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.service.IDataVerificationService;
import com.lecyon.farm.vo.add.AddDataVerificationVo;
import com.lecyon.farm.vo.copy.DuplicateVo;
import com.lecyon.farm.vo.modify.ModifyDataVerificationVo;
import com.lecyon.farm.vo.query.QueryDataVerificationVo;
import com.lecyon.farm.vo.request.IdsVo;
import com.lecyon.farm.vo.view.DataVerificationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 数据核检 Controller
 *
 * @author YaoZheng
 * @since 2020-04-25
 */
@RestController
@RequestMapping("/data-verification")
@Api(tags = "数据核检")
@ResponseBody
@CrossOrigin
public class DataVerificationController {

    private IDataVerificationService dataVerificationService;

    @Autowired
    public DataVerificationController(IDataVerificationService dataVerificationService) {
        this.dataVerificationService = dataVerificationService;
    }

    @ApiOperation(value = "新增数据核检", notes = "新增数据核检，author:YaoZheng")
    @PostMapping(value = "/post")
    public RestResponse<Long> add(@RequestBody @Valid AddDataVerificationVo vo) {
        return dataVerificationService.add(vo);
    }

    @ApiOperation(value = "复制数据核检", notes = "复制数据核检，author:YaoZheng")
    @PostMapping(value = "/duplicate")
    public RestResponse<Long> duplicate(@RequestBody @Valid DuplicateVo vo) {
        return dataVerificationService.duplicate(vo);
    }

    @ApiOperation(value = "编辑数据核检", notes = "编辑数据核检，author:YaoZheng")
    @PostMapping(value = "/put")
    public RestResponse<Long> modify(@RequestBody @Valid ModifyDataVerificationVo vo) {
        return dataVerificationService.modify(vo);
    }

    @ApiOperation(value = "删除数据核检", notes = "删除数据核检(支持批量删除)，author:YaoZheng")
    @PostMapping(value = "/remove")
    public BaseResponse remove(@RequestBody @Valid IdsVo vo) {
        return dataVerificationService.delete(vo);
    }

    @ApiOperation(value = "查看数据核检", notes = "查看数据核检，author:YaoZheng")
    @PostMapping(value = "/get")
    public RestResponse<DataVerificationVo> get(@RequestBody @Valid BaseRequestVo<QueryDataVerificationVo> vo) {
        QueryDataVerificationVo condition = vo.getEntity(QueryDataVerificationVo.class);
        condition.setUserToken(vo.getUserToken());
        return dataVerificationService.get(condition);
    }

    @ApiOperation(value = "查询数据核检列表", notes = "查询数据核检列表(分页)，author:YaoZheng")
    @PostMapping(value = "/getList")
    public RestResponse<Page<DataVerificationVo>> getPageList(@RequestBody @Valid BaseRequestPageVo<QueryDataVerificationVo> vo) {
        return dataVerificationService.getPageList(vo);
    }

    @ApiOperation(value = "查询数据核检下拉列表", notes = "查询数据核检列表(不分页)，author:YaoZheng")
    @PostMapping(value = "/getPullDownList")
    public RestResponse<List<DataVerificationVo>> getList(@RequestBody @Valid BaseRequestVo<QueryDataVerificationVo> vo) {
        return dataVerificationService.getList(vo);
    }

    @ApiOperation(value = "导出查询数据核检列表", notes = "导出查询数据核检列表，author:YaoZheng")
    @PostMapping(value = "/exportList")
    public RestResponse<String> exportList(@RequestBody @Valid BaseRequestVo<QueryDataVerificationVo> vo) {
        return dataVerificationService.exportExcel(vo);
    }

}
